<include file="../header" />
<body class="J_scroll_fixed">
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=FO5BZ-2AC2G-ACAQV-I5BD3-YX65K-76BUB"></script>
    <script src="http://open.map.qq.com/apifiles/v1.0/app.js?v=1.0.131203.1" type="text/javascript"></script>
    <script type="text/javascript">
    $(function() {
        
        $('button#send').click(function () {
            var mobile = $("input[name=mobile]").val();
            var coachName = $("input[name=coachName]").val();
            var idcardNumber = $("input[name=idcardNumber]").val();
            var imageUrl = $("input[name=imageUrl]").val();
            
            if(imageUrl===''||imageUrl===null) {
                layer.msg('请选择文件上传教练头像!');
                return false;
            }
            //验证手机号格式
            if(!mobileValidate($.trim(mobile))) {             
                return false;
            }
            if(coachName===''||coachName===null) {
                layer.msg('教练名称不能为空!');
                return false;
            }
            //验证身份证格式
            if(!identityCodeValidate($.trim(idcardNumber))){
                return false;
            }else{
                $("form#add").submit();
            }
        });

        $("button#upload").click(function(){     
            //上传文件
            $.ajaxFileUpload({
                url:"{:U('shop/uploadImage')}", //处理图片脚本
                secureuri: false,
                fileElementId: 'fileToUpload', //file控件id
                dataType: 'json',
                success: function(data, status) {
                    $("input[name=imageUrl]").val(data);
//                    layer.msg(data);
                    $("img[name=preShow]").attr("src", data);
                },
                error: function(data, status, e) {
                    alert(e);
                }
            })
        })
        
    });
</script>
	<div class="wrap jj">
		<div class="common-form">
			<form  id='add' method="post" class="form-horizontal J_ajaxForm" action="{:U('coach/add_post')}">
                            <input type="hidden" name='id' value="{$coach.coach_id}" />
				<fieldset>
                                        <div class="control-group">
						<label class="control-label">店铺:</label>
						<div class="controls">
							{:getShopSelectHtml($coach['shop_id'])}
						</div>
					</div>
                                        <div class="control-group">
                                            <label class="control-label">教练头像:</label>
                                            <div class="controls">
                                                    <input id="fileToUpload" type="file" name="fileToUpload" style="width:170px;">
                                                    <button type="button" class="btn btn-primary" id="upload">上传</button>
                                                    <input type="hidden" name="imageUrl" value="{$coach.head_image_url}" />
                                            </div>
					</div>
                                        <div class="control-group">
                                            <label class="control-label">头像预览:</label>
                                            <div class="controls">
                                                <img src="{$coach.head_image_url}" name="preShow" style="width:200px;height:200px;" />
                                            </div>
                                        </div>
					<div class="control-group">
						<label class="control-label">手机:</label>
						<div class="controls">
							<input type="text" class="input" name="mobile" value="{$coach.mobile}">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">姓名:</label>
						<div class="controls">
							<input type="text" class="input" name="coachName" value="{$coach.coach_name}">
						</div>
					</div>
					 
					<div class="control-group">
						<label class="control-label">身份证号:</label>
						<div class="controls">
							<input type="text" class="input" name="idcardNumber" value="{$coach.idcard_number}">
						</div>
					</div> 
					<div class="control-group">
						<label class="control-label">性别:</label>
						<div class="controls">
							{:getEnumSelectWidget($gender,'gender',$coach['gender'])}
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">等级:</label>
						<div class="controls">
							{:getCoachLevelSelectHtml($coach['level_id'])}
						</div>
					</div>
				</fieldset>
				
				<div class="form-actions">
					<button id='send' type="button" class="btn btn-primary">添加</button>
					<a class="btn" href="__URL__">返回</a>
				</div>
			</form>
		</div>
	</div>
	<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>